/**
 * @file teaService
 * @date 2024/7/28
 * @author Yi Tao
 * @description Description
 */

// Your code here
/**
 * @description 添加茶叶
 */
Mock.mock("/tea/addTea", "post", function (data) {
    let tea = JSON.parse(data.body);
    console.log(tea);
    let teaArr = JSON.parse(localStorage.getItem("teaArr"));
    if (teaArr == null) {
        teaArr = [];
    }
    for (let i = 0; i < teaArr.length; i++) {
        if (teaArr[i].name == tea.name) {
            return {
                code: 0,
                msg: "茶叶已存在"
            }
        }
    }
    teaArr.push(tea);
    localStorage.setItem("teaArr", JSON.stringify(teaArr));
    return {
        code: 1,
        msg: "添加成功"
    }
})

/**
 * @description 获取茶叶
 */
Mock.mock("/tea/getTeaArr", "get", function () {
    let teaArr = JSON.parse(localStorage.getItem("teaArr"));
    if (teaArr == null) {
        teaArr = [];
    }
    return {
        code: 1,
        msg: "获取成功",
        data: teaArr
    }
})